const Service = require("egg").Service;

class GradeService extends Service {
    /**
     * 添加教室
     * @param {*} name
     * @param {*} topic
     * @param {*} room_id
     */
    async add(name, topic, room_id) {
        let sql = "insert into grade (name, topic, room_id) values (?, ?, ?)";
        let params = [name, topic, room_id];
        let res = await this.app.mysql.query(sql, params);
        return res;
    }

    async readList() {
        let sql = `
            select
            g.*, r.sn as room_name 
            from grade as g
            join room as r on g.room_id = r.id
        `;
        let res = await this.app.mysql.query(sql);
        return res;
    }

    async find(id) {
        let sql = "select * from grade where id = ?";
        let params = [id];
        let res = await this.app.mysql.query(sql, params);
        return res[0];
    }
}

module.exports = GradeService;
